<?php
class MY_Controller_admin extends CI_Controller{
    
    public function __construct() {
        parent::__construct();
        
               $this->load->library('ion_auth');
		$this->load->library('form_validation');
		$this->load->helper('url');

		// Load MongoDB library instead of native db driver if required
		$this->config->item('use_mongodb', 'ion_auth') ?
		$this->load->library('mongo_db') :

		$this->load->database();

		$this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));

		$this->lang->load('auth');
		$this->load->helper('language');
                
              

        
    }
  
    
 
    
    final public function _render($view = 'admin/index', $data=array(), $render=false){
        
        
        //$data['title']='Главная';
         $this->load->helper('url');
       // $data['menu'] = $this->menu_model->get_menu();
        
       
        
        $this->load->view('admin/header', $data);
       //  $this->load->view('admin/left_menu', $data);
        $this->load->view($view, $data , $render);
        $this->load->view('admin/footer');
        
    }
    
    //авторизация
    /*
    public function _render_page($view, $data=null, $render=false)
	{

		$this->viewdata = (empty($data)) ? $this->data: $data;

		$view_html = $this->load->view($view, $this->viewdata, $render);

		if (!$render) return $view_html;
	}
 
  */  
    
   public function _validate(){
                 //------------------------------------------------------------------------------------------
          
                if (!$this->ion_auth->logged_in())
		{
			//redirect them to the login page
			redirect('/admin/admin/login', 'refresh');
		}
		elseif (!$this->ion_auth->is_admin())
		{
			//redirect them to the home page because they must be an administrator to view this
			redirect('/', 'refresh');
		}
		else
		{
		
                            redirect('/admin/admin', 'refresh');
			//$this->_render('admin/auth/index', $this->data);
                 
                 
		}
                
                return;
        //---------------------------------------------------------------------------------------------------------------------------------        
               
                
   } 
 function _get_csrf_nonce()
	{
		$this->load->helper('string');
		$key   = random_string('alnum', 8);
		$value = random_string('alnum', 20);
		$this->session->set_flashdata('csrfkey', $key);
		$this->session->set_flashdata('csrfvalue', $value);

		return array($key => $value);
	}

	function _valid_csrf_nonce()
	{
		if ($this->input->post($this->session->flashdata('csrfkey')) !== FALSE &&
			$this->input->post($this->session->flashdata('csrfkey')) == $this->session->flashdata('csrfvalue'))
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}   
   
    
    
    
    
}




?>
